package com.catazy.mvvmlib.ext.download

/**
 * 作者: Tao
 * 日期: 2024/1/31
 * 时间: 15:25
 * 描述: 下载结果状态密封类
 */
sealed class DownloadResultState {
    companion object {
        /**
         * 下载等待
         */
        fun onPending(): DownloadResultState = Pending

        /**
         * 下载进度
         */
        fun onProgress(soFarBytes: Long, totalBytes: Long, progress: Int): DownloadResultState =
            Progress(soFarBytes, totalBytes, progress)

        /**
         * 下载成功
         */
        fun onSuccess(filePath: String, totalBytes: Long): DownloadResultState =
            Success(filePath, totalBytes)

        /**
         * 下载暂停
         */
        fun onPause(): DownloadResultState = Pause

        /**
         * 下载错误
         */
        fun onError(errorMsg: String): DownloadResultState = Error(errorMsg)
    }


    object Pending : DownloadResultState()

    data class Progress(val soFarBytes: Long, val totalBytes: Long, val progress: Int) :
        DownloadResultState()

    data class Success(val filePath: String, val totalBytes: Long) : DownloadResultState()

    object Pause : DownloadResultState()

    data class Error(val errorMsg: String) : DownloadResultState()
}